package 网络编程.Text;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.function.BiFunction;

public class TCPText6 {
    public static void main(String[] args) throws IOException {
        //客户端:将本地文件上传到服务器,并接收服务器的反馈
        //服务端:接收客户端上传的文件,上传完毕给于反馈

        ServerSocket ss=new ServerSocket(10006);

        //监控客户端的连接
        Socket accept = ss.accept();
        //生成随机id
        String replace = UUID.randomUUID().toString().replace("-", "");
        //关联保存客户端数据的路径

        BufferedOutputStream bo=new BufferedOutputStream(new FileOutputStream("D:\\idea2022\\day.com.qiezi\\day_13\\src\\网络编程\\Text\\"+replace+".jpg"));
        BufferedInputStream bi=new BufferedInputStream(accept.getInputStream());

        int a;
        byte[] bytes=new byte[1024];
        while ((a=bi.read(bytes))!=-1){
            bo.write(bytes,0,a);
        }
        //给与反馈
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        //释放资源
        bw.close();
        bo.close();
        accept.close();
        ss.close();
    }
}
